package de.ubschmidt.capi;

import java.nio.ByteBuffer;

/**
 *
 */
public class ConnectB3Ind
        extends CapiPassiveMessage
        implements NcciAccessor {

    private static final int OFFSET_NCCI = OFFSET_MESSAGE;
    private static final int OFFSET_NCPI = OFFSET_NCCI + SIZE_OF_NCCI;

    /**
     * Create a new {@code ConnectB3Ind} message from the specified
     * {@code ByteBuffer}.
     *
     * @param byteBuffer A {@code ByteBuffer} containing a CONNECT_B3_REQ CAPI
     *                   message.
     */
    public ConnectB3Ind(final ByteBuffer byteBuffer) {
        super(byteBuffer);
    }

    /** {@inheritDoc} */
    public int getNcci() {
        return getByteBuffer().getInt(OFFSET_NCCI);
    }

    /**
     * Retrieve the Network Control Protocol Information (NCPI).
     *
     * The meaning of the parameter NCPI depends on the protocol.
     *
     * @return The NCPI.
     */
    public CapiStruct getNcpi() {
        ByteBuffer byteBuffer = getByteBuffer();
        byteBuffer.position(OFFSET_NCPI);

        return new CapiStruct(byteBuffer);
    }

    /** {@inheritDoc} */
    @Override
    public String toString() {
        String s = String.format(
                "%s[%s ncci=0x%08x ncpi=%s]",
                getClass().getSimpleName(),
                super.toString(),
                getNcci(),
                getNcpi());

        return s;
    }

}
